<template>
  <div id="app">
    <div class="container">
      <div class="close"><span class="iconfont iconicon-test"></span></div>
      <div class="logo"><span class="iconfont iconnew"></span></div>
      <div class="inputs">
        <!-- v-model:
              作用1:双向绑定表单元素的value属性
              作用2:v-model会自动绑定并接收input事件传递过来的值,并且把值同步给v-model绑定的变量 
              
             这里的v-model做了两件事
                1.讲username传递给子组件(相当于之前的v-bind:value="username"
                2.自动绑定了input1事件(相当于之前写的@getData='setUsername')-->
        <hmInput
          :reg="/^[1][3,4,5,7,8][0-9]{9}$/"
          placeholder="手机号码"
          v-model="user.username"
        ></hmInput>
        <hmInput placeholder="请输入密码" v-model="user.password"></hmInput>
      </div>
      <p class="tips">
        没有账号？
        <a href="#/register" class="">去注册</a>
      </p>
      <!-- <div class="button">登录按钮</div> -->
      <van-button icon="star-o" round type="danger" block @click="loginFn"
        >登录</van-button
      >
    </div>
  </div>
</template>

<script>
import hmInput from "../components/hmInput.vue";
import { login } from "../api/user.js";
export default {
  data() {
    return {
      user: {
        username: "",
        password: "",
      },
    };
  },
  components: {
    hmInput,
  },
  methods: {
    // setUsername(val) {
    //   // 子组件传值给父组件,父组件接收之后赋值给username
    //   this.user.username = val;
    // },

    loginFn() {
      login(this.user)
        .then((res) => {
          if (res.data.message == "用户不存在") {
            this.$toast.fail(res.data.message);
          } else {
            this.$toast.fail(res.data.message);
            // 跳转首页
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang='less' scoped>
.container {
  padding: 20px;
}
.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}
.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}
.inputs {
  input {
    margin-bottom: 20px;
  }
}
.tips {
  text-align: right;
  margin-bottom: 20px;
  a {
    color: #3385ff;
  }
}
</style>